/*
 * URL.cpp
 *
 *  Created on: Apr 13, 2011
 *      Author: nathanielclinger
 */

#include <iostream>
#include <string>
#include <sstream>
#include "URL.hpp"
//#include "Comment.hpp"

using namespace std;

URL::URL()
{
	url = "" ;
	plus = 0 ;
	minus = 0 ;
}

URL::URL( string s )
{
	url = s ;
	plus = 0 ;
	minus = 0 ;
}

URL::URL( URL &other )
{
	url = other.url ;
	plus = other.plus ;
	minus = other.minus ;

//	for( int i = 0 ; i < other.comments.length() ; i++ )
//		comments.add( other.comments.get( i ) ) ;
}


/*void setURL( string str ) { url = str ; }	// set and get URL
string getURL() { return url ; }

void votePlus() { plus++ ; }		// deal with vote crap
void voteMinus() { minus++ ; }
int getPlus() { return plus ; }
int getMinus() { return minus ; }

void addComment( string s )
{
//	Comment temp( s ) ;
//	comments.add( temp ) ;
//	cout << "comments.length: " << comments.length() << endl ;
}

string getComment( int n )
{
//	return comments.get( n ).getComment() ;
}

int numComments()
{
//	return comments.length() ;
}*/

char * getWebsiteName()
{
	char * s = new char[10] ;
	strcpy( s, "Website name" ) ;
	return s ;
}

char * getStars()
{
	char * str = new char[400] ;
	int plus = 10 ;
	int minus = 5 ;
	double p = plus/(plus+minus) ;
	p *= 5 ;
	strcpy( str, " " ) ;
	for( int i = 0 ; i < 5 ; i++ )
	{
		if( i < p )
			strcat( str, "<a href=\".\"><img class=\"star\" src=\"./images/star.png\" /></a>" ) ;
		else
			strcat( str, "<a href=\".\"><img class=\"star\" src=\"./images/starempty.png\" /></a>" ) ;
	}

	return str ;
}

char * getDate()
{
	char * s = new char[10] ;
	strcpy( s, "26 April 2011" ) ;
	return s ;
}

char * getCategory()
{
	char * s = new char[10] ;
	strcpy( s, "Category" ) ;
	return s ;
}

char * getFirstComment()
{
	char * s = new char[10] ;
	strcpy( s, "some comment about stuff............." ) ;
	return s ;
}

char * getURL()
{
	char * s = new char[100] ;
	strcpy( s, "http://communityseo.com/wp-content/uploads/2010/12/website-design.jpg" ) ;
	return s ;
}

char * getWebsitePic()
{
	char * s = new char[10] ;
	strcpy( s, "./images/screen01.png" ) ;
	return s ;
}

int getTotalVisits()
{
	return 1438 ;
}

int getUniqueVisits()
{
	return 535 ;
}


int getPositiveVotes()
{
	return 10 ;
}

int getNegativeVotes()
{
	return 5 ;
}

int getTotalVotes()
{
	int p = getPositiveVotes() ;
	int n = getNegativeVotes() ;
	int t = p + n ;
	return t ;
}

ostream& operator<<( ostream& os, const URL& other )
{
	os << "<div class=\"contentbox\"><table class=\"contenttablehead\"><tr><td class=\"contentleft\">" ;
	os << "<h2><a href=\"" << getWebsiteName() << "\">" << getWebsiteName() ;

	os << "</a></h2></td><td class=\"contentright\">"
			<< getStars() ;

	os << "</td></tr><tr><td class=\"tdauthor\"><p>" ;

	os << "Added on " << getDate() << " in "
		<< "<a href=\".\" class=\"category\">" << getCategory() ;

	os << "</a></p></td><td class=\"tdratings\"><p>" ;

	os << "Total of " << getTotalVotes() << " votes" ;

	os << "</p></td></tr></table><table class=\"contenttable\"><tr><td class=\"contentleft\">" ;

	os << "<p><a href=\"" << getURL() << "\">" << getURL() << "</a></p><hr />" ;

	os << "<h3>Latest Comment</h3><p>" << getFirstComment() ;

	os << "<a href=\"/" << getWebsiteName() << "\" class=\"readmore\">Read more</a></p>"
		<< "<a href=\"/" << getWebsiteName() << "\" class=\"replies\">See all</a><a href=\"/"
		<< getWebsiteName() << "\" class=\"replies\">Post a reply</a><a href=\"/"
		<< getWebsiteName() << "\" class=\"replies\">Post a new comment</a>" ;

	os << "<hr /><h3>Rate this website</h3><a href=\".\">"
		<< "<img class=\"vote\" src=\"./images/voteyes.png\" /></a>"
		<< "<a href=\".\"><img class=\"vote\" src=\"./images/voteno.png\" /></a></td><!--contentleft-->" ;


	os << "<td class=\"contentright\"><div>"
			<< "<a href=\"/" << getWebsiteName()
			<< "\"><img class\\=\"screenshot\" src=\""
			<< getWebsitePic() << "\" /></a></div>" ;

	os << "<div class=\"stats\"><div style=\"padding:1px 20px 10px 20px;\"><h3>Website Stats</h3><table class=\"statstable\"><tr><td class=\"statsleft\">"
		<< "Total Visits</td><td class=\"statsright\">" << getTotalVisits() << "</td></tr><tr><td class=\"statsleft\">"
		<< "Unique Visits</td><td class=\"statsright\">" << getUniqueVisits() << "</td></tr><tr><td class=\"statsleft\">"
		<< "Total Votes</td><td class=\"statsright\">" << getTotalVotes() << "</td></tr><tr><td class=\"statsleft\">"
		<< "Positive Votes</td><td class=\"statsright\">" << getPositiveVotes() << "</td></tr><tr><td class=\"statsleft\">"
		<< "Negative Votes</td><td class=\"statsright\">" << getNegativeVotes() << "</td></tr></table></div></div>"
		<< "</td></tr></table></div>" ;

	return os ;
}
